home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / effects / effectClasses / ZoomInstance.as < prev   
Text File  |  2014-03-27  |  10KB  |  317 lines

  1. package mx.effects.effectClasses
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.MouseEvent;
  5.    import mx.core.mx_internal;
  6.    import mx.effects.EffectManager;
  7.    import mx.events.FlexEvent;
  8.    
  9.    use namespace mx_internal;
  10.    
  11.    public class ZoomInstance extends TweenEffectInstance
  12.    {
  13.       
  14.       mx_internal static const VERSION:String = "3.0.0.0";
  15.        
  16.       
  17.       private var newY:Number;
  18.       
  19.       public var originY:Number;
  20.       
  21.       private var origX:Number;
  22.       
  23.       private var origY:Number;
  24.       
  25.       public var originX:Number;
  26.       
  27.       private var origPercentHeight:Number;
  28.       
  29.       public var zoomWidthFrom:Number;
  30.       
  31.       public var zoomWidthTo:Number;
  32.       
  33.       private var newX:Number;
  34.       
  35.       public var captureRollEvents:Boolean;
  36.       
  37.       private var origPercentWidth:Number;
  38.       
  39.       public var zoomHeightFrom:Number;
  40.       
  41.       private var origScaleX:Number;
  42.       
  43.       public var zoomHeightTo:Number;
  44.       
  45.       private var origScaleY:Number;
  46.       
  47.       private var scaledOriginX:Number;
  48.       
  49.       private var scaledOriginY:Number;
  50.       
  51.       private var show:Boolean = true;
  52.       
  53.       private var _mouseHasMoved:Boolean = false;
  54.       
  55.       public function ZoomInstance(param1:Object)
  56.       {
  57.          super(param1);
  58.       }
  59.       
  60.       override public function finishEffect() : void
  61.       {
  62.          if(captureRollEvents)
  63.          {
  64.             target.removeEventListener(MouseEvent.ROLL_OVER,mouseEventHandler,false);
  65.             target.removeEventListener(MouseEvent.ROLL_OUT,mouseEventHandler,false);
  66.             target.removeEventListener(MouseEvent.MOUSE_MOVE,mouseEventHandler,false);
  67.          }
  68.          super.finishEffect();
  69.       }
  70.       
  71.       private function getScaleFromWidth(param1:Number) : Number
  72.       {
  73.          return param1 / (target.width / Math.abs(target.scaleX));
  74.       }
  75.       
  76.       override public function initEffect(param1:Event) : void
  77.       {
  78.          super.initEffect(param1);
  79.          if(param1.type == FlexEvent.HIDE || param1.type == Event.REMOVED)
  80.          {
  81.             show = false;
  82.          }
  83.       }
  84.       
  85.       private function getScaleFromHeight(param1:Number) : Number
  86.       {
  87.          return param1 / (target.height / Math.abs(target.scaleY));
  88.       }
  89.       
  90.       private function applyPropertyChanges() : void
  91.       {
  92.          var _loc2_:Boolean = false;
  93.          var _loc3_:Boolean = false;
  94.          var _loc1_:PropertyChanges = propertyChanges;
  95.          if(_loc1_)
  96.          {
  97.             _loc2_ = false;
  98.             _loc3_ = false;
  99.             if(_loc1_.end["scaleX"] !== undefined)
  100.             {
  101.                zoomWidthFrom = !!isNaN(zoomWidthFrom) ? Number(target.scaleX) : Number(zoomWidthFrom);
  102.                zoomWidthTo = !!isNaN(zoomWidthTo) ? Number(_loc1_.end["scaleX"]) : Number(zoomWidthTo);
  103.                _loc3_ = true;
  104.             }
  105.             if(_loc1_.end["scaleY"] !== undefined)
  106.             {
  107.                zoomHeightFrom = !!isNaN(zoomHeightFrom) ? Number(target.scaleY) : Number(zoomHeightFrom);
  108.                zoomHeightTo = !!isNaN(zoomHeightTo) ? Number(_loc1_.end["scaleY"]) : Number(zoomHeightTo);
  109.                _loc3_ = true;
  110.             }
  111.             if(_loc3_)
  112.             {
  113.                return;
  114.             }
  115.             if(_loc1_.end["width"] !== undefined)
  116.             {
  117.                zoomWidthFrom = !!isNaN(zoomWidthFrom) ? Number(getScaleFromWidth(target.width)) : Number(zoomWidthFrom);
  118.                zoomWidthTo = !!isNaN(zoomWidthTo) ? Number(getScaleFromWidth(_loc1_.end["width"])) : Number(zoomWidthTo);
  119.                _loc2_ = true;
  120.             }
  121.             if(_loc1_.end["height"] !== undefined)
  122.             {
  123.                zoomHeightFrom = !!isNaN(zoomHeightFrom) ? Number(getScaleFromHeight(target.height)) : Number(zoomHeightFrom);
  124.                zoomHeightTo = !!isNaN(zoomHeightTo) ? Number(getScaleFromHeight(_loc1_.end["height"])) : Number(zoomHeightTo);
  125.                _loc2_ = true;
  126.             }
  127.             if(_loc2_)
  128.             {
  129.                return;
  130.             }
  131.             if(_loc1_.end["visible"] !== undefined)
  132.             {
  133.                show = _loc1_.end["visible"];
  134.             }
  135.          }
  136.       }
  137.       
  138.       private function mouseEventHandler(param1:MouseEvent) : void
  139.       {
  140.          if(param1.type == MouseEvent.MOUSE_MOVE)
  141.          {
  142.             _mouseHasMoved = true;
  143.          }
  144.          else if(param1.type == MouseEvent.ROLL_OUT || param1.type == MouseEvent.ROLL_OVER)
  145.          {
  146.             if(!_mouseHasMoved)
  147.             {
  148.                param1.stopImmediatePropagation();
  149.             }
  150.             _mouseHasMoved = false;
  151.          }
  152.       }
  153.       
  154.       override public function play() : void
  155.       {
  156.          super.play();
  157.          applyPropertyChanges();
  158.          if(isNaN(zoomWidthFrom) && isNaN(zoomWidthTo) && isNaN(zoomHeightFrom) && isNaN(zoomHeightTo))
  159.          {
  160.             if(show)
  161.             {
  162.                zoomWidthFrom = zoomHeightFrom = 0;
  163.                zoomWidthTo = target.scaleX;
  164.                zoomHeightTo = target.scaleY;
  165.             }
  166.             else
  167.             {
  168.                zoomWidthFrom = target.scaleX;
  169.                zoomHeightFrom = target.scaleY;
  170.                zoomWidthTo = zoomHeightTo = 0;
  171.             }
  172.          }
  173.          else
  174.          {
  175.             if(isNaN(zoomWidthFrom) && isNaN(zoomWidthTo))
  176.             {
  177.                zoomWidthFrom = zoomWidthTo = target.scaleX;
  178.             }
  179.             else if(isNaN(zoomHeightFrom) && isNaN(zoomHeightTo))
  180.             {
  181.                zoomHeightFrom = zoomHeightTo = target.scaleY;
  182.             }
  183.             if(isNaN(zoomWidthFrom))
  184.             {
  185.                zoomWidthFrom = target.scaleX;
  186.             }
  187.             else if(isNaN(zoomWidthTo))
  188.             {
  189.                zoomWidthTo = zoomWidthFrom == 1 ? Number(0) : Number(1);
  190.             }
  191.             if(isNaN(zoomHeightFrom))
  192.             {
  193.                zoomHeightFrom = target.scaleY;
  194.             }
  195.             else if(isNaN(zoomHeightTo))
  196.             {
  197.                zoomHeightTo = zoomHeightFrom == 1 ? Number(0) : Number(1);
  198.             }
  199.          }
  200.          if(zoomWidthFrom < 0.01)
  201.          {
  202.             zoomWidthFrom = 0.01;
  203.          }
  204.          if(zoomWidthTo < 0.01)
  205.          {
  206.             zoomWidthTo = 0.01;
  207.          }
  208.          if(zoomHeightFrom < 0.01)
  209.          {
  210.             zoomHeightFrom = 0.01;
  211.          }
  212.          if(zoomHeightTo < 0.01)
  213.          {
  214.             zoomHeightTo = 0.01;
  215.          }
  216.          origScaleX = target.scaleX;
  217.          origScaleY = target.scaleY;
  218.          newX = origX = target.x;
  219.          newY = origY = target.y;
  220.          if(isNaN(originX))
  221.          {
  222.             scaledOriginX = target.width / 2;
  223.          }
  224.          else
  225.          {
  226.             scaledOriginX = originX * origScaleX;
  227.          }
  228.          if(isNaN(originY))
  229.          {
  230.             scaledOriginY = target.height / 2;
  231.          }
  232.          else
  233.          {
  234.             scaledOriginY = originY * origScaleY;
  235.          }
  236.          scaledOriginX = Number(scaledOriginX.toFixed(1));
  237.          scaledOriginY = Number(scaledOriginY.toFixed(1));
  238.          origPercentWidth = target.percentWidth;
  239.          if(!isNaN(origPercentWidth))
  240.          {
  241.             target.width = target.width;
  242.          }
  243.          origPercentHeight = target.percentHeight;
  244.          if(!isNaN(origPercentHeight))
  245.          {
  246.             target.height = target.height;
  247.          }
  248.          tween = createTween(this,[zoomWidthFrom,zoomHeightFrom],[zoomWidthTo,zoomHeightTo],duration);
  249.          if(captureRollEvents)
  250.          {
  251.             target.addEventListener(MouseEvent.ROLL_OVER,mouseEventHandler,false);
  252.             target.addEventListener(MouseEvent.ROLL_OUT,mouseEventHandler,false);
  253.             target.addEventListener(MouseEvent.MOUSE_MOVE,mouseEventHandler,false);
  254.          }
  255.       }
  256.       
  257.       override public function onTweenEnd(param1:Object) : void
  258.       {
  259.          var _loc2_:Number = NaN;
  260.          var _loc3_:Number = NaN;
  261.          if(!isNaN(origPercentWidth))
  262.          {
  263.             _loc2_ = target.width;
  264.             target.percentWidth = origPercentWidth;
  265.             if(target.parent && target.parent.autoLayout == false)
  266.             {
  267.                target.mx_internal::_width = _loc2_;
  268.             }
  269.          }
  270.          if(!isNaN(origPercentHeight))
  271.          {
  272.             _loc3_ = target.height;
  273.             target.percentHeight = origPercentHeight;
  274.             if(target.parent && target.parent.autoLayout == false)
  275.             {
  276.                target.mx_internal::_height = _loc3_;
  277.             }
  278.          }
  279.          super.onTweenEnd(param1);
  280.          if(mx_internal::hideOnEffectEnd)
  281.          {
  282.             EffectManager.suspendEventHandling();
  283.             target.scaleX = origScaleX;
  284.             target.scaleY = origScaleY;
  285.             target.move(origX,origY);
  286.             EffectManager.resumeEventHandling();
  287.          }
  288.       }
  289.       
  290.       override public function onTweenUpdate(param1:Object) : void
  291.       {
  292.          EffectManager.suspendEventHandling();
  293.          if(Math.abs(newX - target.x) > 0.1)
  294.          {
  295.             origX += Number(target.x.toFixed(1)) - newX;
  296.          }
  297.          if(Math.abs(newY - target.y) > 0.1)
  298.          {
  299.             origY += Number(target.y.toFixed(1)) - newY;
  300.          }
  301.          target.scaleX = param1[0];
  302.          target.scaleY = param1[1];
  303.          var _loc2_:Number = param1[0] / origScaleX;
  304.          var _loc3_:Number = param1[1] / origScaleY;
  305.          var _loc4_:Number = scaledOriginX * _loc2_;
  306.          var _loc5_:Number = scaledOriginY * _loc3_;
  307.          newX = scaledOriginX - _loc4_ + origX;
  308.          newY = scaledOriginY - _loc5_ + origY;
  309.          newX = Number(newX.toFixed(1));
  310.          newY = Number(newY.toFixed(1));
  311.          target.move(newX,newY);
  312.          tween.mx_internal::needToLayout = true;
  313.          EffectManager.resumeEventHandling();
  314.       }
  315.    }
  316. }
  317.